package com.itheima.controller;

import com.itheima.Service.ServiceImpl.AdminPetService;
import com.itheima.pojo.PageBean;
import com.itheima.pojo.Pet;
import com.itheima.pojo.PetQueryParam;
import com.itheima.pojo.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RequestMapping("/admin_pets")
@RestController
public class AdminPetController {

    @Autowired
    private AdminPetService adminPetService;

    /**
     * 宠物列表分页查询
     *
     * @param petQueryParam
     * @return
     */
    @GetMapping
    public Result page(PetQueryParam petQueryParam) {
        log.info("data:{}", petQueryParam);
        PageBean pageBean = adminPetService.page(petQueryParam);
        return Result.success(pageBean);
    }

    /**
     * 门店查询每个门店所有宠物
     *
     * @return
     */
//    @GetMapping("/{id}")
//    public Result findAll(@PathVariable Integer id) {
//        List<Pet> petList = adminPetService.findAll(id);
//        return Result.success(petList);
//    }

    /**
     * 根据Id删除宠物
     *
     * @param id
     * @return
     */
    @DeleteMapping
    public Result deleteById(@RequestParam Integer id) {
        log.info("删除的宠物id{}", id);
        adminPetService.deleteById(id);
        return Result.success();
    }

    /**
     * 添加宠物
     *
     * @param pet
     * @return
     */
    @PostMapping
    public Result addPet(@RequestBody Pet pet) {
        log.info("要添加的宠物{}", pet);
        adminPetService.addPet(pet);
        return Result.success();
    }

    @GetMapping("/{id}")
    public Result selectById_admin(@PathVariable Integer id) {
        log.info("要修改的宠物id：{}",id);
        Pet pet = adminPetService.selectId(id);
        return Result.success(pet);
    }

    @PutMapping
    public Result update(@RequestBody Pet pet){
        log.info("{}",pet);
        adminPetService.update(pet);
        return Result.success();
    }
}
